package com.hghivln.erpwarehouse.business.controller;


import com.hghivln.erpwarehouse.business.entity.Sales;
import com.hghivln.erpwarehouse.business.service.SalesService;
import com.hghivln.erpwarehouse.business.vo.SalesVo;
import com.hghivln.erpwarehouse.system.common.lang.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hghivln
 * @since 2021-07-13
 */
@RestController
@RequestMapping("api/sales")
public class SalesController {

    @Autowired
    private SalesService salesService;

    @RequestMapping("loadAllSales")
    public Object loadAllSales(SalesVo salesVo) {
        return salesService.QueryAllSales(salesVo);
    }

    @RequiresPermissions("sales:add")
    @RequestMapping("addSales")
    public Result addSales(Sales sales) {
        try {
            salesService.saveSales(sales);
            return Result.ADD_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return Result.ADD_ERROR;
        }
    }

    @RequiresPermissions("sales:update")
    @RequestMapping("updateSales")
    public Result updateSales(Sales sales) {
        try {
            salesService.updateById(sales);
            return Result.UPDATE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return Result.UPDATE_ERROR;
        }
    }

}
